#include <stdio.h>
#include <stdarg.h>
#include <apr_pools.h>
#include <apr_strings.h>
/*! \file log.c
 *  \brief Log File
 *   The Log Module  generates log messages in order to facilitate program monitoring
*/
static apr_pool_t *log_pool;
static int debug_on = 0;

void log_init(int debug)
{
	debug_on = debug;
	apr_pool_create(&log_pool, NULL);
	apr_pool_tag(log_pool, "log");
}

void error(const char *message, ...)
{
	char *formatted_msg;
	va_list argp;

	va_start(argp, message);
	formatted_msg = apr_pvsprintf(log_pool, message, argp); 
	va_end(argp);
	fprintf(stderr, "[ERROR] %s\n", formatted_msg);
	apr_pool_clear(log_pool);
}
/*debug mssgs*/
void debug(const char *message, ...)
{
	char *formatted_msg;
	va_list argp;

	if (!debug_on) return;

	va_start(argp, message);
	formatted_msg = apr_pvsprintf(log_pool, message, argp); 
	va_end(argp);
	fprintf(stderr, "[DEBUG] %s\n", formatted_msg);
	apr_pool_clear(log_pool);
}
